﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;

namespace Tireguit.Nmon.Parser.Dict
{
    public class NmonElementsDictionnary:SortedDictionary<BaliseType,INmonElement>,IDisposable
    {
        protected ILog _log=LogManager.GetLogger(typeof(NmonElementsDictionnary));
        protected bool disposed = false;
        protected virtual void Dispose(bool disposing)
        {
            try
            {
                _log.Debug("start Dispose");
                if (!disposed)
                {
                    if (disposing)
                    {
                        BaliseType[] keys=this.Keys.ToArray();
                        foreach (var key in keys)
                        {
                            this[key].Dispose();
                            this.Remove(key);
                        }
                    }
                    disposed=true;
                }
            }
            catch (System.Exception ex)
            {
            	_log.Error("Dispose",ex);
            }
            finally
            {
                _log.Debug("stop Dispose");
            }
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        ~NmonElementsDictionnary()
        {
            Dispose(false);
        }
    }
}
